import {defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'

function resolve(dir: string) {
    return path.join(__dirname, './', dir)
}
// https://vite.dev/config/
// @ts-ignore
export default defineConfig({
    plugins: [react()],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src'), // 设置 @ 别名指向 src 目录
        },
    },
    css: {
        modules: {
            hashPrefix: 'prefix',
            generateScopedName: '[name]__[local]__[hash:base64:5]',
        },
        preprocessorOptions: {
            less: {
                modifyVars: {
                    hack: `true; @import (reference) "${resolve('src/assets/css/global.less')}";`,
                },
                javascriptEnabled: true,
            },
        },
    },
    server:{
        proxy: {
            // 选项写法
            '/web': {
                target: 'https://sqzbx-test.etib.cn/newzbx', // 目标服务器地址
                changeOrigin: true, // 是否启用代理路径重写
                // rewrite: (path) => path.replace(/^\/web/, 'ahb'), // 重写请求路径
            },
        },
        historyApiFallback:true
    }
})
